<template>
	<view>
		<view class="wrap">

		</view>
	</view>
</template>

<script>
	import {
		request,
		requestData
	} from '@/utils/http.js'
	export default {
		data() {
			return {
				latitude: '',
				longitude: '',
				name: '',
				address: '',
			}
		},
		onLoad(option) {
			// 重置导航栏样式（若有动态修改）
			// uni.setNavigationBarTitle({
			// 	title: '位置' // 确保标题存在
			// });
			// setTimeout(() => {
			// 	this.initSiteInfo()
			// }, 1000)
			this.initSiteInfo()
		},
		onShow() {

		},
		onUnload() {
			// console.log('返回到home')
			// uni.switchTab({
			// 	url: '/pages/home/index',
			// })
		},
		methods: {
			initSiteInfo() {
				request('/common/site/info', {
						site_code: '17001',
						with_images: 1,
					})
					.then((res) => {
						this.latitude = res.datas.latitude
						this.longitude = res.datas.longitude
						this.name = res.datas.name
						this.city = res.datas.city
						this.address = res.datas.address
						this.goToLocation()
					})
					.catch((err) => {
						console.log(err)
					})
			},
			goToLocation() {
				// this.latitude = 39.986342
				// this.longitude = 116.355033
				uni.openLocation({
					latitude: this.latitude,
					longitude: this.longitude,
					name: this.site_name,
					address: this.city + '市' + this.address,
					success() {
						//console.log('导航成功')

					},
					fail(err) {
						console.error('导航失败', err)
						uni.showToast({
							title: '导航失败',
							icon: 'none',
						})
					},
				})

			}
		}
	}
</script>

<style>
	/* .wrap {
		width: 100%;
		height: 100vh;
	}

	.uni-navigation-bar {
		display: block;
	} */
</style>